home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mib / mibToggle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-20  |  4.3 KB  |  179 lines

  1. #include "mibload.h"
  2. #include "mibwidgets.h"
  3.  
  4. extern Display    *dpy;
  5. extern GC     mib_gc;
  6.  
  7. /* Code for Toggle */
  8. /*****************************************************************************/
  9.  
  10. mib_Widget *mib_create_Toggle(mib_Widget *parent, char *name, char *label,
  11.         int posx, int posy, int width, int height, int mib_fill)
  12. {
  13.   mib_Widget *temp;
  14.   mib_Toggle *myres;
  15.   unsigned char *label_text;
  16.   Arg     args[20];
  17.   int     n;
  18.  
  19.   /* create the new widget and add it to the tree */
  20.  
  21.   temp = mib_new_mib_Widget();
  22.   if (mib_fill == WDEFAULT)
  23.     mib_add_backward(temp, parent);
  24.   else
  25.     mib_add_mib_Widget(temp, parent);
  26.  
  27.   myres = (mib_Toggle *)malloc(sizeof(mib_Toggle));
  28.  
  29.   /* initialize public resources */
  30.  
  31.   if (mib_fill == WDEFAULT)
  32.   {
  33.     temp->name = (char *)malloc(strlen(name)+1);
  34.     strcpy(temp->name,name);
  35.   }
  36.   temp->mib_class = (char *)malloc(7);
  37.   sprintf(temp->mib_class,"Toggle");
  38.   temp->mib_class_num = MIB_TOGGLE;
  39.   temp->width = 0 /*width*/;
  40.   temp->height = 0 /*height*/;
  41.   temp->topOffset = posy;
  42.   temp->leftOffset = posx;
  43.   temp->bottomOffset = 0;
  44.   temp->rightOffset = 0;
  45.   temp->topAttachment = 1;
  46.   temp->leftAttachment = 1;
  47.   temp->bottomAttachment = 0;
  48.   temp->rightAttachment = 0;
  49.  
  50.   temp->mib_allowresize = 0;
  51.  
  52.   /* initialize private resources */
  53.  
  54.   temp->myres = (void *)myres;
  55.  
  56.   myres->isize = 0;
  57.   if (mib_fill == WDEFAULT)
  58.   {
  59.     myres->label = (char *)malloc(strlen(label)+1);
  60.     strcpy(myres->label,label);
  61.   }
  62.  
  63.   /* create Xt widget */
  64.  
  65.   n = 0;
  66.  
  67.   if (mib_fill == WDEFAULT)
  68.   {
  69.     label_text = XmStringCreateLtoR(label, XmSTRING_DEFAULT_CHARSET);
  70.  
  71.     XtSetArg (args[n], XmNlabelString, label_text); n++;
  72.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  73.     XtSetArg (args[n], XmNleftOffset, posx);n++;
  74.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  75.     XtSetArg (args[n], XmNtopOffset, posy);n++;
  76. /*    XtSetArg (args[n], XmNwidth, width); n++;
  77.     XtSetArg (args[n], XmNheight, height); n++;*/
  78.   }
  79.  
  80.   XtSetArg (args[n], XmNwidth, width); n++;
  81.   XtSetArg (args[n], XmNheight, height); n++;
  82.   XtSetArg (args[n], XmNspacing, 4); n++;
  83.   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  84.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  85.   XtSetArg (args[n], XmNindicatorType, XmN_OF_MANY);
  86.  
  87.   temp->me = XtCreateManagedWidget(name, xmToggleButtonWidgetClass,
  88.                 temp->parent->me, args, n);
  89.  
  90.   if (mib_fill == WDEFAULT)
  91.   {
  92.     XmStringFree(label_text);
  93.   }
  94.  
  95.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  96.   {
  97.     mib_apply_eventhandlers(temp->me, temp);
  98.   }
  99.  
  100.   return temp;
  101. }
  102.  
  103. void mib_delete_Toggle(mib_Widget *this)
  104. {
  105.   mib_Toggle *temp = (mib_Toggle *)this->myres;
  106.  
  107.   free(temp->label);
  108.   free(temp);
  109. }
  110.  
  111. void mib_save_Toggle(mib_Widget *this, FILE *fout)
  112. {
  113.   mib_Toggle *temp = (mib_Toggle *)this->myres;
  114.  
  115.   fprintf(fout,"label: \\\"%s\\\"\\n\\\n", temp->label);
  116.   fprintf(fout,"indicatorSize: %d\\n\\\n", temp->isize);
  117. }
  118.  
  119. int mib_load_Toggle(mib_Widget *this, mib_Buffer *fin)
  120. {
  121.   mib_Toggle    *myres;
  122.   unsigned char *label_text;
  123.   char          res[MI_MAXSTRLEN];
  124.   char          val[MI_MAXSTRLEN];
  125.   Arg           args[20];
  126.   int           n, got_line, vallen;
  127.  
  128.   myres = (mib_Toggle *)this->myres;
  129.  
  130.   got_line = mib_read_line(fin, res, val);
  131.   if (!got_line)
  132.     return 0;
  133.  
  134.   if (!strcmp(res,"label"))
  135.   {
  136.     vallen = strlen(val);
  137.     if (vallen < 2)
  138.       return 0;
  139.     val[vallen-1] = '\0';
  140.     myres->label = (char *)malloc(vallen-1);
  141.     sprintf(myres->label,"%s",&(val[1]));
  142.  
  143.     label_text = XmStringCreateLtoR(myres->label, XmSTRING_DEFAULT_CHARSET);
  144.  
  145.     n = 0;
  146.     XtSetArg (args[n], XmNlabelString, label_text); n++;
  147.     this->width = 0;
  148.     this->height = 0;
  149.     XtSetArg (args[n], XmNwidth, this->width); n++;
  150.     XtSetArg (args[n], XmNheight, this->height); n++;
  151.     XtSetValues(this->me, args, n);
  152.     XmStringFree(label_text);
  153.  
  154.   }
  155.   else
  156.     return 0;
  157.  
  158.   got_line = mib_read_line(fin, res, val);
  159.   if (!got_line)
  160.     return 0;
  161.  
  162.   if (!strcmp(res, "indicatorSize"))
  163.   {
  164.     sscanf(val, "%d", &(myres->isize));
  165.     if (myres->isize)
  166.       XtVaSetValues(this->me, XmNindicatorSize, (Dimension)myres->isize,
  167.           XmNmarginBottom, 0, XmNmarginTop, 0, XmNmarginLeft, 0,
  168.           XmNmarginRight, 0, XmNspacing, 0, NULL);
  169.     got_line = mib_read_line(fin, res, val);
  170.     if (!got_line)
  171.       return 0;
  172.   }
  173.  
  174.   if (strcmp(res,"EndWidget"))
  175.     return 0;
  176.  
  177.   return 1;
  178. }
  179.